package com.luhui.codereview.swing

import com.intellij.ui.components.JBPanel
import com.luhui.codereview.getMessage
import com.luhui.codereview.token.LocalUserInfo
import com.luhui.codereview.token.LocalUserInfoHodler
import com.luhui.codereview.token.LocalUserManager
import javax.swing.JButton
import javax.swing.JLabel
import javax.swing.JTextField

/**
 * 用户个人信息tab
 * @author  luhui
 * @date  2019/11/18 22:11
 * @version 1.0
 */
class SelfUserTab : JBPanel<JBPanel<*>>(){

    val realNameText = JTextField()
    val emailText = JTextField()

    init {
        this.layout = null
        val realNameLbl = JLabel(getMessage("realNameLbl.text"))
        realNameLbl.setBounds(50,20,80,30)
        this.add(realNameLbl)
        val emailLbl = JLabel(getMessage("emailLbl.text"))
        emailLbl.setBounds(50,50,80,30)
        this.add(emailLbl)


        realNameText.setBounds(110, 20, 200, 30)
        this.add(realNameText)

        emailText.setBounds(110, 50, 200, 30)
        this.add(emailText)

        val saveBtn = JButton(getMessage("userInfoSaveBtn.text"))
        saveBtn.setBounds(160,80,60,30)
        this.add(saveBtn)
        saveBtn.addActionListener{
            val localUserInfo = LocalUserInfo()
            localUserInfo.id = LocalUserInfoHodler.localUserInfo?.id
            localUserInfo.realName = realNameText.text
            localUserInfo.email = emailText.text
            LocalUserInfoHodler.localUserInfo = localUserInfo
            LocalUserManager.saveLocalUserInfo()
        }
    }
}